from abc import abstractclassmethod
from .MyLogger import MyLogger
from .Instruction import Instruction

class InvokeInstruction(Instruction):
    def __init__(self) -> None:
        self.instSymbol:str = ''
        self.helpInfo:str = ''
        self.args:str = ''
    
    def GetHelp(self) -> str:
        usage = ''
        if self.args:
            usage = '\n' + ' ' * 6 + 'usage:    -' + self.instSymbol + ' ' + self.args
        return f'-{self.instSymbol:<14} {self.helpInfo}{usage}'

g_invokeInstTable:dict[str, InvokeInstruction] = {}

def invoke_auto_add(cls):
    inst:InvokeInstruction = cls()
    g_invokeInstTable[inst.instSymbol] = inst
    return cls

def GetInvokeInstTable():
    return g_invokeInstTable

def GetInvokeOptStr():
    optStr = ''
    for item in g_invokeInstTable.values():
        optStr += item.instSymbol
        if item.args:
            optStr += ':'
    return optStr